import 'package:flutter/widgets.dart';

extension TextEditingControllerExt on TextEditingController {
  enter(String input) {
    if (selection.isValid) {
      text = text.replaceRange(
        selection.start,
        selection.end,
        input,
      );
    } else {
      text = "$text$input";
    }
  }

  backspace() {
    if (text.isEmpty) {
      return;
    } else if (selection.isValid) {
      enter("");
    } else {
      final runes = text.runes;
      final newRunes = runes.take(runes.length - 1);
      text = String.fromCharCodes(newRunes);
    }
  }
}
